/**
 * @Author: wangliuyang
 * @Date: 2021/9/7 20:35
 * @Description:1221. 分割平衡字符串
 */
public class Solution_1221 {
    public int balancedStringSplit(String s) {
        int ans = 0;
        int count = 0;
        for (int i = 0; i < s.length(); i++){
            if (s.charAt(i) == 'L'){
                count++;
            }else {
                count--;
            }
            if (count == 0){
                ans++;
            }
        }
        return ans;
    }
}
